import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;

public class ParseDom {
    public static void main(String[] args) {
        Document dom=Jsoup.parse(getHtml());
        StringBuffer sb=new StringBuffer();
        sb.append("> ");
        sb.append(dom.select("h2.fs16").text());
        sb.append("\n\n");
        sb.append("### url\n");
        sb.append("`/bus/"+dom.select(".dataTmpItem").attr("data-item-target")+".json`\n");
        sb.append("\n### request\n");
        sb.append("字段 | 类型 | 说明\n--- | -- | --\n");
        Elements eles=dom.select(".paramsBox");
        Elements trs=eles.get(0).select("tbody tr");
        if (trs != null) {
            for(Element e:trs){
                Elements tds=e.select("td");
                sb.append(tds.get(0).text()+" | "+tds.get(1).text()+" | "+tds.get(2).text()+"\n");
            }
        }
        sb.append("\n### response\n");
        sb.append("字段 | 类型 | 说明\n--- | -- | --\n");
        trs=eles.get(1).select("tbody tr");
        if (trs != null) {
            for(Element e:trs){
                Elements tds=e.select("td");
                sb.append(tds.get(0).text()+" | "+tds.get(1).text()+" | "+tds.get(2).text()+"\n");
            }
        }
        System.out.println(sb.toString());
    }

    private static String getHtml(){
        return "<div class=\"dataTmpItem\" data-item-target=\"getQrCodeImg\">\n" +
                "        <h2 class=\"fs16\">《获取二维码邀请图片》 getQrCodeImg</h2>\n" +
                "        <div class=\"dataParams\">\n" +
                "            <h3 class=\"fs14 fc6\">request</h3>\n" +
                "            <div class=\"paramsBox\">\n" +
                "                <table>\n" +
                "                    <thead>\n" +
                "                        <tr>\n" +
                "                            <th>字段</th>\n" +
                "                            <th>类型</th>\n" +
                "                            <th>说明</th>\n" +
                "                        </tr>\n" +
                "                    </thead>\n" +
                "                    <tbody>\n" +
                "                    </tbody>\n" +
                "                </table>\n" +
                "            </div>\n" +
                "            <h3 class=\"fs14 fc6\">response</h3>\n" +
                "            <div class=\"paramsBox\">\n" +
                "                <table>\n" +
                "                    <thead>\n" +
                "                        <tr>\n" +
                "                            <th>字段</th>\n" +
                "                            <th>类型</th>\n" +
                "                            <th>说明</th>\n" +
                "                        </tr>\n" +
                "                    </thead>\n" +
                "                    <tbody>\n" +
                "                        <tr class=\"forServer \"><td>success</td><td>[Boolean]</td><td>返回状态,true或false</td></tr>\n" +
                "                        <tr class=\"forServer \"><td>msg</td><td>[string]</td><td>错误信息,success为false时存在</td></tr>\n" +
                "                        <tr class=\"forServer \"><td>qrCodeImg</td><td>[string]</td><td>二维码图片</td></tr>\n" +
                "                    </tbody>\n" +
                "                </table>\n" +
                "            </div>\n" +
                "        </div>\n" +
                "    </div>";
    }
}
